from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-12-16 14:03:32.430376
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 16, Dec, 2021
Time: 14:03:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.5266
Nobs: 507.000 HQIC: -47.9828
Log likelihood: 5853.65 FPE: 1.08020e-21
AIC: -48.2772 Det(Omega_mle): 9.06065e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.355157 0.079295 4.479 0.000
L1.Burgenland 0.099583 0.043945 2.266 0.023
L1.Kärnten -0.115205 0.022625 -5.092 0.000
L1.Niederösterreich 0.178918 0.091124 1.963 0.050
L1.Oberösterreich 0.127527 0.092331 1.381 0.167
L1.Salzburg 0.282827 0.047278 5.982 0.000
L1.Steiermark 0.021577 0.061025 0.354 0.724
L1.Tirol 0.107687 0.049309 2.184 0.029
L1.Vorarlberg -0.081917 0.043411 -1.887 0.059
L1.Wien 0.029723 0.082974 0.358 0.720
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.011127 0.175298 0.063 0.949
L1.Burgenland -0.050166 0.097151 -0.516 0.606
L1.Kärnten 0.036445 0.050018 0.729 0.466
L1.Niederösterreich -0.211055 0.201449 -1.048 0.295
L1.Oberösterreich 0.468220 0.204118 2.294 0.022
L1.Salzburg 0.314058 0.104519 3.005 0.003
L1.Steiermark 0.104109 0.134909 0.772 0.440
L1.Tirol 0.311285 0.109009 2.856 0.004
L1.Vorarlberg 0.010032 0.095970 0.105 0.917
L1.Wien 0.016057 0.183432 0.088 0.930
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.220064 0.040336 5.456 0.000
L1.Burgenland 0.091305 0.022354 4.084 0.000
L1.Kärnten -0.004968 0.011509 -0.432 0.666
L1.Niederösterreich 0.223072 0.046353 4.812 0.000
L1.Oberösterreich 0.167877 0.046968 3.574 0.000
L1.Salzburg 0.037322 0.024050 1.552 0.121
L1.Steiermark 0.027213 0.031043 0.877 0.381
L1.Tirol 0.076842 0.025083 3.064 0.002
L1.Vorarlberg 0.055598 0.022083 2.518 0.012
L1.Wien 0.106980 0.042208 2.535 0.011
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160257 0.039408 4.067 0.000
L1.Burgenland 0.042323 0.021840 1.938 0.053
L1.Kärnten -0.012576 0.011244 -1.118 0.263
L1.Niederösterreich 0.152011 0.045287 3.357 0.001
L1.Oberösterreich 0.344649 0.045887 7.511 0.000
L1.Salzburg 0.100921 0.023496 4.295 0.000
L1.Steiermark 0.109149 0.030328 3.599 0.000
L1.Tirol 0.087177 0.024506 3.557 0.000
L1.Vorarlberg 0.053780 0.021575 2.493 0.013
L1.Wien -0.038242 0.041236 -0.927 0.354
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.148724 0.075610 1.967 0.049
L1.Burgenland -0.038258 0.041903 -0.913 0.361
L1.Kärnten -0.036094 0.021574 -1.673 0.094
L1.Niederösterreich 0.130116 0.086889 1.497 0.134
L1.Oberösterreich 0.188515 0.088040 2.141 0.032
L1.Salzburg 0.255960 0.045081 5.678 0.000
L1.Steiermark 0.076461 0.058189 1.314 0.189
L1.Tirol 0.130875 0.047018 2.784 0.005
L1.Vorarlberg 0.105182 0.041394 2.541 0.011
L1.Wien 0.041299 0.079118 0.522 0.602
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.078177 0.059857 1.306 0.192
L1.Burgenland 0.016043 0.033173 0.484 0.629
L1.Kärnten 0.051180 0.017079 2.997 0.003
L1.Niederösterreich 0.179908 0.068787 2.615 0.009
L1.Oberösterreich 0.337017 0.069698 4.835 0.000
L1.Salzburg 0.050780 0.035689 1.423 0.155
L1.Steiermark -0.005639 0.046066 -0.122 0.903
L1.Tirol 0.125029 0.037222 3.359 0.001
L1.Vorarlberg 0.059247 0.032770 1.808 0.071
L1.Wien 0.109754 0.062634 1.752 0.080
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.169957 0.072577 2.342 0.019
L1.Burgenland 0.011457 0.040222 0.285 0.776
L1.Kärnten -0.060861 0.020708 -2.939 0.003
L1.Niederösterreich -0.112153 0.083404 -1.345 0.179
L1.Oberösterreich 0.233500 0.084509 2.763 0.006
L1.Salzburg 0.038633 0.043273 0.893 0.372
L1.Steiermark 0.262996 0.055855 4.709 0.000
L1.Tirol 0.489287 0.045132 10.841 0.000
L1.Vorarlberg 0.070704 0.039734 1.779 0.075
L1.Wien -0.100645 0.075944 -1.325 0.185
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.141692 0.080336 1.764 0.078
L1.Burgenland -0.013062 0.044523 -0.293 0.769
L1.Kärnten 0.063462 0.022923 2.769 0.006
L1.Niederösterreich 0.173399 0.092321 1.878 0.060
L1.Oberösterreich -0.079352 0.093544 -0.848 0.396
L1.Salzburg 0.224213 0.047899 4.681 0.000
L1.Steiermark 0.134585 0.061827 2.177 0.029
L1.Tirol 0.052659 0.049957 1.054 0.292
L1.Vorarlberg 0.141138 0.043982 3.209 0.001
L1.Wien 0.164999 0.084064 1.963 0.050
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.456327 0.044496 10.255 0.000
L1.Burgenland -0.000775 0.024660 -0.031 0.975
L1.Kärnten -0.013646 0.012696 -1.075 0.282
L1.Niederösterreich 0.179359 0.051134 3.508 0.000
L1.Oberösterreich 0.262739 0.051811 5.071 0.000
L1.Salzburg 0.019690 0.026530 0.742 0.458
L1.Steiermark -0.011177 0.034244 -0.326 0.744
L1.Tirol 0.071368 0.027670 2.579 0.010
L1.Vorarlberg 0.056283 0.024360 2.310 0.021
L1.Wien -0.018580 0.046561 -0.399 0.690
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.028819 0.093147 0.155235 0.140632 0.066768 0.080929 0.014627 0.209081
Kärnten 0.028819 1.000000 -0.034619 0.130857 0.049537 0.074403 0.455878 -0.080157 0.097625
Niederösterreich 0.093147 -0.034619 1.000000 0.280763 0.100328 0.253884 0.050368 0.143175 0.247956
Oberösterreich 0.155235 0.130857 0.280763 1.000000 0.194272 0.284732 0.159973 0.125893 0.185735
Salzburg 0.140632 0.049537 0.100328 0.194272 1.000000 0.120382 0.060795 0.109191 0.066718
Steiermark 0.066768 0.074403 0.253884 0.284732 0.120382 1.000000 0.132178 0.089005 0.008148
Tirol 0.080929 0.455878 0.050368 0.159973 0.060795 0.132178 1.000000 0.063842 0.127218
Vorarlberg 0.014627 -0.080157 0.143175 0.125893 0.109191 0.089005 0.063842 1.000000 -0.009386
Wien 0.209081 0.097625 0.247956 0.185735 0.066718 0.008148 0.127218 -0.009386 1.000000